package cjyyp.day01;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

@Slf4j
public class 线程创建 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //第一种
        Thread t1=new Thread(){
            @Override
            public void run() {
                log.debug("线程1启动");
            }
        };
        t1.start();
        //第二种
        Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
                log.debug("线程2启动");
            }
        });
        t2.start();

        //第三种
        FutureTask<Integer> futureTask=new FutureTask(new Callable() {
            @Override
            public Object call() throws Exception {
                log.debug("线程3启动");
                Thread.sleep(1000);
                return 520;
            }
        });
        Thread t3=new Thread(futureTask);
        t3.start();

        log.debug("主线程启动");
        log.debug("拿到结果：{}",futureTask.get());
    }
}
